package cn.blunce.weather.models;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;

import cn.blunce.weather.models.CityIDDao;
import cn.blunce.weather.models.WeatherIDDao;
import cn.blunce.weather.models.WeatherMessageDao;
import cn.blunce.weather.models.WeatherAQIDao;
import cn.blunce.weather.models.DailyForcastDao;
import cn.blunce.weather.models.AstroWeatherDao;
import cn.blunce.weather.models.WeatherDailyDao;
import cn.blunce.weather.models.WeatherTmpDao;
import cn.blunce.weather.models.WeatherWindDao;
import cn.blunce.weather.models.HourlyForcastDao;
import cn.blunce.weather.models.WeatherNowDao;
import cn.blunce.weather.models.WeatherNowCondDao;
import cn.blunce.weather.models.WeatherSuggestionDao;
import cn.blunce.weather.models.SuggestionDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * Master of DAO (schema version 1): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    /** Creates underlying database table using DAOs. */
    public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
        CityIDDao.createTable(db, ifNotExists);
        WeatherIDDao.createTable(db, ifNotExists);
        WeatherMessageDao.createTable(db, ifNotExists);
        WeatherAQIDao.createTable(db, ifNotExists);
        DailyForcastDao.createTable(db, ifNotExists);
        AstroWeatherDao.createTable(db, ifNotExists);
        WeatherDailyDao.createTable(db, ifNotExists);
        WeatherTmpDao.createTable(db, ifNotExists);
        WeatherWindDao.createTable(db, ifNotExists);
        HourlyForcastDao.createTable(db, ifNotExists);
        WeatherNowDao.createTable(db, ifNotExists);
        WeatherNowCondDao.createTable(db, ifNotExists);
        WeatherSuggestionDao.createTable(db, ifNotExists);
        SuggestionDao.createTable(db, ifNotExists);
    }
    
    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
        CityIDDao.dropTable(db, ifExists);
        WeatherIDDao.dropTable(db, ifExists);
        WeatherMessageDao.dropTable(db, ifExists);
        WeatherAQIDao.dropTable(db, ifExists);
        DailyForcastDao.dropTable(db, ifExists);
        AstroWeatherDao.dropTable(db, ifExists);
        WeatherDailyDao.dropTable(db, ifExists);
        WeatherTmpDao.dropTable(db, ifExists);
        WeatherWindDao.dropTable(db, ifExists);
        HourlyForcastDao.dropTable(db, ifExists);
        WeatherNowDao.dropTable(db, ifExists);
        WeatherNowCondDao.dropTable(db, ifExists);
        WeatherSuggestionDao.dropTable(db, ifExists);
        SuggestionDao.dropTable(db, ifExists);
    }
    
    public static abstract class OpenHelper extends SQLiteOpenHelper {

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }
    
    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }

    public DaoMaster(SQLiteDatabase db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(CityIDDao.class);
        registerDaoClass(WeatherIDDao.class);
        registerDaoClass(WeatherMessageDao.class);
        registerDaoClass(WeatherAQIDao.class);
        registerDaoClass(DailyForcastDao.class);
        registerDaoClass(AstroWeatherDao.class);
        registerDaoClass(WeatherDailyDao.class);
        registerDaoClass(WeatherTmpDao.class);
        registerDaoClass(WeatherWindDao.class);
        registerDaoClass(HourlyForcastDao.class);
        registerDaoClass(WeatherNowDao.class);
        registerDaoClass(WeatherNowCondDao.class);
        registerDaoClass(WeatherSuggestionDao.class);
        registerDaoClass(SuggestionDao.class);
    }
    
    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }
    
    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }
    
}
